package com.itany.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
import java.io.IOException;

/**
 * Author：汤小洋
 * Date：2022-11-10 15:20
 * Description：<描述>
 */
@WebFilter(urlPatterns = "/data", initParams = {
        @WebInitParam(name = "name",value = "lisi")
})
public class HelloFilter implements Filter {

    public HelloFilter(){
        System.out.println("HelloFilter被实例化。。。。。。");
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("HelloFilter初始化。。。。。。"+filterConfig.getInitParameter("name"));
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("HelloFilter在调用目标资源之前，进行处理操作。。。。。。");

        // 将请求交给下一个过滤器进行处理，如果已经是最后一个过滤器，则调用目标资源
        filterChain.doFilter(servletRequest,servletResponse);

        System.out.println("HelloFilter在调用目标资源之后，进行处理操作。。。。。。");
    }

    @Override
    public void destroy() {
        System.out.println("HelloFilter即将被销毁。。。。。。");

    }
}
